<template>
  <div id="homeUserInfo">
    <div class="grid-header grid-header-bq companyinfo">
      <span class="iconfont icons">&#xe725;</span>
      <span class="companyName">{{ userDetail.abbreviationName ? userDetail.abbreviationName : userDetail.subName }}</span>
    </div>
    <div class="grid-box">
      <div class="grid-box-lf">
        <img v-if="userDetail.headPortrait" :src="userDetail.headPortrait" alt="" />
        <img v-if="!userDetail.headPortrait && userDetail.gender == 1" src="@/assets/images/homeImages/man.png" alt="" />
        <img v-if="!userDetail.headPortrait && userDetail.gender == 0" src="@/assets/images/homeImages/man.png" alt="" />
      </div>
      <div class="grid-box-rt">
        <p>
          <span class="names">{{ userDetail.realName }}</span> &nbsp;<span>{{ userDetail.departmentName }}</span>
        </p>
        <p>{{ userDetail.position ? userDetail.position : "暂无职位" }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      //用户详细信息
      userDetail: {},
    };
  },
  computed: {
    ...mapState({
      userInfo: (state) => state.common.userInfo,
    }),
  },
  methods: {
    getUserInfo() {
      this.$api.publicApi
        .GetLoginUserSpecificInfo({ userId: this.userInfo.userid })
        .then((res) => {
          this.userDetail = res.data.data;
          this.userDetail.gender = this.userDetail.gender ?? 0;
          this.loading.close();
        })
        .catch(() => {
          this.loading.close();
        });
    },
  },
  activated() {
    this.getUserInfo();
  },
  mounted() {
    this.loading = this.$loading({
      target: document.getElementById("homeUserInfo"),
      text: "加载中...",
      customClass: "loading",
    });
    this.getUserInfo();
  },
};
</script>
<style lang="less" scoped>
#homeUserInfo {
  :deep(.loading) {
    .el-loading-spinner {
      p {
        text-align: center;
      }
    }
  }
  .grid-header {
    color: #333333;
    height: 40px;
    line-height: 40px;
    font-size: 14px;
  }
  .grid-header-bq {
    background-image: url("../../../assets/images/homeImages/EnterpriseBq.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    color: #ffffff;
    font-size: 15px;
    border-radius: 10px 10px 0px 0px;
    height: 50px;
    & > span {
      margin-left: 50px;
    }
  }
  .companyinfo {
    display: flex;
    flex-flow: row;
    justify-content: flex-start;
    align-items: center;
    .icons {
      margin-left: 20px;
      font-size: 16px;
    }
    .companyName {
      margin-left: 8px;
      font-size: 16px;
    }
  }
  .grid-box {
    height: 12vh;
    display: flex;
    align-items: center;
    .grid-box-lf {
      width: 60px;
      height: 60px;
      margin-left: 20px;
      margin-right: 20px;
      box-shadow: 0 2px 12px 0 rgb(0 0 0 / 2%);
      border-radius: 4px;

      img {
        width: 100%;
        height: 100%;
        border-radius: 12px;
      }
      // background-color: red;
    }
    .grid-box-rt {
      flex: 1;
      height: 60px;
      line-height: 30px;
      font-size: 13px;
      color: #303133;
      .names {
        font-size: 20px;
        font-weight: 500;
        color: #303133;
      }
    }
  }
}
</style>
